package com.teach.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.CertificateInfoSearch;
import com.teach.entity.CertificateInfo;
import com.teach.exception.CodeException;
import com.teach.mapper.CertificateInfoMapper;
import com.teach.service.CertificateInfoService;
@Service
public class CertificateInfoServiceImpl implements CertificateInfoService{

	@Autowired
	private CertificateInfoMapper mapper;
	
	@Autowired
	private CertificateInfoService certificateInfoService;
	

	@Override
	public List<CertificateInfo> listAll() {
		return mapper.selectAll();
	}

	@Override
	public CertificateInfo getInfoId(Long infoId) {
		return mapper.selectByPrimaryKey(infoId);
	}

	@Override
	public String add(CertificateInfo certificateInfo) {
		mapper.insertSelective(certificateInfo);
		int i = mapper.insertSelective(certificateInfo);
		String message="";
		if(i>0) {
			message="添加成功";
		}else {
			message="添加失败";
		}
		return message;
	}

	@Override
	public void update(CertificateInfo certificateInfo) {
		mapper.updateByPrimaryKey(certificateInfo);
		
	}

	@Override
	public String delete(Long infoId) {

		int i = mapper.deleteByPrimaryKey(infoId);
		String message="";
		if(i>0) {
			message="删除成功";
		}else {
			message="删除失败";
		}
		return message;

	}

	@Override
	public CertificateInfo getinfoCertificateId(Long infoCertificateId) {
		try {
			return mapper.select(infoCertificateId);
		} catch (Exception e) {
			throw new CodeException(3000);
		}
	}

	@Override
	public CertificateInfo getinfoName(String infoName) {
		return certificateInfoService.getinfoName(infoName);
	}
	
	@Override
	public List<CertificateInfo> list(CertificateInfoSearch search) {
		PageInfo<CertificateInfo> page = PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->{
			mapper.selectPage(search);
		});
		return page.getList();
	}
	@Override
	public PageInfo<CertificateInfo> page(CertificateInfoSearch search) {
		PageInfo<CertificateInfo> page = PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->{
			mapper.selectPage(search);
		});
		return page;
	}

	//通过info-Pass和info-status查询
		@Override
		public List<CertificateInfo> getinfoStatus(String infoPass,Integer infoStatus) {
			return mapper.selectByinfoStatus(infoPass, infoStatus);
		}

		@Override
		public List<CertificateInfo> getInfoPass(String infoPass,Integer infoStatus) {
			return mapper.selectByinfoPass(infoPass, infoStatus);
		}

		//查询是否认证
		@Override
		public List<CertificateInfo> getinfoStatus(Integer infoStatus) {
			return mapper.selectByinfoStatus2( infoStatus);
		}

		@Override
		public List<CertificateInfo> getinfoStatus3(Integer infoStatus) {
			return mapper.selectByinfoStatus3( infoStatus);
		}
	

}
